from django.contrib.auth.models import Group
from rest_framework.permissions import BasePermission





class TeacherPermission(BasePermission):


    def has_permission(self, request, view):
        user = request.user
        # 获取老师组
        group = Group.objects.get(name='老师')
        # 获取用户所在组
        groups = user.groups.all()

        return bool(user.is_superuser or group in groups)